/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ComputingPanel.java
 *
 * Created on 2011-12-09, 00:15:33
 */
package jobscheduling.gui;

import info.monitorenter.gui.chart.Chart2D;
import info.monitorenter.gui.chart.ITrace2D;
import info.monitorenter.gui.chart.io.ADataCollector;
import info.monitorenter.gui.chart.traces.Trace2DLtd;
import java.awt.Color;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Map;
import java.util.TreeMap;
import javax.swing.JFrame;
import jobscheduling.model.Computation;
import jobscheduling.model.Problem;

/**
 *
 * @author Dawid
 */
public class ComputingPanel extends javax.swing.JFrame {
    protected Problem _problem;
    protected Map<String, String> _bees;
    protected Map<String, String> _pso;
    protected Map<String, String> _glowworm;
    protected Map<String, Integer> _iterations = new TreeMap<String, Integer>();
    
    protected int _beesIterations;
    protected int _psoIterations;
    protected int _glowwormIterations;
    protected int _selectedCheckBox;
    
    protected int _realTimeBorder;
    protected Collector _beeCollector;
    protected Collector _psoCollector;
    protected Collector _glowCollector;
    protected JFrame _beeFrame;
    protected JFrame _psoFrame;
    protected JFrame _glowFrame;
    
    protected Computation _computation;
    
    /** Creates new form ComputingPanel */
    public ComputingPanel(Problem problem, Map<String,String> bees, 
                          Map<String, String> pso, Map<String, String> glow, int selectedCheckBoxOnStart) {
        super(problem.getName()); 
        
        _problem = problem;
        _beesIterations = Integer.parseInt(bees.get("cycleCount"));
        _bees = bees;
        _psoIterations = Integer.parseInt(pso.get("iterations"));
        _pso = pso;
        _glowwormIterations = Integer.parseInt(glow.get("iterations"));
        _glowworm = glow;
        
        _realTimeBorder = problem.getBestSolution()*2;
        
        initComponents();
        
        _iterations.put(GUI.BEES, 0);
        _iterations.put(GUI.PSO, 0);
        _iterations.put(GUI.GW, 0);
        
        switch(selectedCheckBoxOnStart){
            case 0:
                beeCheckBox.setSelected(true);
                psoCheckBox.setSelected(true);
                glowWormCheckBox.setSelected(true);
                _computation = new Computation (problem, bees, pso, glow, this);
                break;
            case 1:
                beeCheckBox.setSelected(true);
                _computation = new Computation (problem, bees, null, null, this);
                break;
            case 2:
                psoCheckBox.setSelected(true);
                _computation = new Computation (problem, null, pso, null, this);
                break;
            case 3:
                glowWormCheckBox.setSelected(true);
                _computation = new Computation (problem, null, null, glow, this);
                break;
        }
    }
    
    public synchronized void finish (String algorithm){
        if (algorithm == null ? GUI.BEES == null : algorithm.equals(GUI.BEES)){
            beeStatusLabel.setText("Done!");
            beeProgressBar.setValue(100);
            
        } else if (algorithm == null ? GUI.PSO == null : algorithm.equals(GUI.PSO)){
            psoStatusLabel.setText("Done!");
            psoProgressBar.setValue(100);
        } else if (algorithm == null ? GUI.GW == null : algorithm.equals(GUI.GW)){
            glowwormStatusLabel.setText("Done!");
            glowwormProgressBar.setValue(100);
        }
        _selectedCheckBox--;
        if(_selectedCheckBox == 0)
            start.setEnabled(true);
    }
    
    public synchronized void nextIteration(String algorithm, int bestTime){
        Integer get = _iterations.get(algorithm);
        if (algorithm.equals(GUI.BEES)){
            beeScore.setText(String.valueOf(bestTime));
            beeIteration.setText(String.valueOf(get));
            beeProgressBar.setValue(100 * get/_beesIterations);
            if(_beeCollector != null)
                _beeCollector.putValue(get, bestTime);
        } else if (algorithm.equals(GUI.PSO)){
            psoScore.setText(String.valueOf(bestTime));
            psoIteration.setText(String.valueOf(get));
            psoProgressBar.setValue(100 * get/_psoIterations);
            if(_psoCollector != null)
                _psoCollector.putValue(get, bestTime);
        } else if (algorithm.equals(GUI.GW)){
            glowwormScore.setText(String.valueOf(bestTime));
            glowwormIteration.setText(String.valueOf(get));
            glowwormProgressBar.setValue(100 * get/_glowwormIterations);
            if(_glowCollector != null)
                _glowCollector.putValue(get, bestTime);
        }
        _iterations.put(algorithm, get + 1);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        beePanel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        beeProgressBar = new javax.swing.JProgressBar();
        beeScore = new javax.swing.JLabel();
        beeIteration = new javax.swing.JLabel();
        beeStatusLabel = new javax.swing.JLabel();
        beeRealTimeScore = new javax.swing.JButton();
        psoPanel = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        psoProgressBar = new javax.swing.JProgressBar();
        psoScore = new javax.swing.JLabel();
        psoIteration = new javax.swing.JLabel();
        psoStatusLabel = new javax.swing.JLabel();
        psoRealTimeScore = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        glowwormProgressBar = new javax.swing.JProgressBar();
        glowwormScore = new javax.swing.JLabel();
        glowwormIteration = new javax.swing.JLabel();
        glowwormStatusLabel = new javax.swing.JLabel();
        glowwormRealTimeScore = new javax.swing.JButton();
        start = new javax.swing.JButton();
        psoCheckBox = new javax.swing.JCheckBox();
        beeCheckBox = new javax.swing.JCheckBox();
        glowWormCheckBox = new javax.swing.JCheckBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Computing...");

        beePanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Bee"));

        jLabel1.setText("score:");

        jLabel2.setText("iteration:");

        beeProgressBar.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        beeScore.setText("0");

        beeIteration.setText("0");

        beeRealTimeScore.setText("Real Time Score");
        beeRealTimeScore.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                beeRealTimeScoreActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout beePanelLayout = new javax.swing.GroupLayout(beePanel);
        beePanel.setLayout(beePanelLayout);
        beePanelLayout.setHorizontalGroup(
            beePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(beePanelLayout.createSequentialGroup()
                .addGroup(beePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(beePanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(beePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(beePanelLayout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(beeScore, javax.swing.GroupLayout.DEFAULT_SIZE, 322, Short.MAX_VALUE))
                            .addGroup(beePanelLayout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(beeIteration, javax.swing.GroupLayout.DEFAULT_SIZE, 322, Short.MAX_VALUE))))
                    .addGroup(beePanelLayout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(beeProgressBar, javax.swing.GroupLayout.DEFAULT_SIZE, 284, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(beeStatusLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(beePanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(beeRealTimeScore)))
                .addContainerGap())
        );

        beePanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel1, jLabel2});

        beePanelLayout.setVerticalGroup(
            beePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(beePanelLayout.createSequentialGroup()
                .addGroup(beePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(beeScore))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(beePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(beeIteration))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(beePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(beeStatusLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 15, Short.MAX_VALUE)
                    .addComponent(beeProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(beeRealTimeScore)
                .addContainerGap())
        );

        psoPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("PSO"));

        jLabel4.setText("score:");

        jLabel5.setText("iteration:");

        psoScore.setText("0");

        psoIteration.setText("0");

        psoRealTimeScore.setText("Real Time Score");
        psoRealTimeScore.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                psoRealTimeScoreActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout psoPanelLayout = new javax.swing.GroupLayout(psoPanel);
        psoPanel.setLayout(psoPanelLayout);
        psoPanelLayout.setHorizontalGroup(
            psoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(psoPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(psoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(psoPanelLayout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(psoIteration, javax.swing.GroupLayout.DEFAULT_SIZE, 322, Short.MAX_VALUE))
                    .addGroup(psoPanelLayout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(psoScore, javax.swing.GroupLayout.DEFAULT_SIZE, 322, Short.MAX_VALUE))
                    .addGroup(psoPanelLayout.createSequentialGroup()
                        .addGap(8, 8, 8)
                        .addComponent(psoProgressBar, javax.swing.GroupLayout.DEFAULT_SIZE, 284, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(psoStatusLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(psoRealTimeScore))
                .addContainerGap())
        );

        psoPanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel4, jLabel5});

        psoPanelLayout.setVerticalGroup(
            psoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(psoPanelLayout.createSequentialGroup()
                .addGroup(psoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(psoScore))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(psoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(psoIteration))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(psoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(psoStatusLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 14, Short.MAX_VALUE)
                    .addComponent(psoProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(psoRealTimeScore)
                .addContainerGap())
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Glow-worm"));

        jLabel6.setText("score:");

        jLabel7.setText("iteration:");

        glowwormScore.setText("0");

        glowwormIteration.setText("0");

        glowwormRealTimeScore.setText("Real Time Score");
        glowwormRealTimeScore.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                glowwormRealTimeScoreActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(glowwormScore, javax.swing.GroupLayout.DEFAULT_SIZE, 322, Short.MAX_VALUE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(glowwormIteration, javax.swing.GroupLayout.DEFAULT_SIZE, 322, Short.MAX_VALUE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(8, 8, 8)
                        .addComponent(glowwormProgressBar, javax.swing.GroupLayout.DEFAULT_SIZE, 284, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(glowwormStatusLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(glowwormRealTimeScore))
                .addContainerGap())
        );

        jPanel3Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel6, jLabel7});

        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(glowwormScore, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(glowwormIteration))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(glowwormStatusLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 14, Short.MAX_VALUE)
                    .addComponent(glowwormProgressBar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(glowwormRealTimeScore)
                .addContainerGap())
        );

        start.setText("Start");
        start.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startActionPerformed(evt);
            }
        });

        psoCheckBox.setText("PSO Computing");

        beeCheckBox.setText("Bee Computing");

        glowWormCheckBox.setText("Glow-worm Computing");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(glowWormCheckBox)
                    .addComponent(psoPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(beePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(beeCheckBox)
                    .addComponent(psoCheckBox)
                    .addComponent(start))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(beeCheckBox)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(beePanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(psoCheckBox)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(psoPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(glowWormCheckBox)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(start)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void beeRealTimeScoreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_beeRealTimeScoreActionPerformed
    if(!_computation.isAlive())
        return;
    
    Chart2D chart = new Chart2D();
    ITrace2D trace = new Trace2DLtd(_realTimeBorder*2);
    trace.setColor(Color.RED);
    chart.addTrace(trace);

    _beeFrame = new JFrame("Bee Real Time Score");
    _beeFrame.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    _beeFrame.getContentPane().add(chart);
    _beeFrame.setSize(400, 300);
    _beeFrame.setVisible(true);
    _beeCollector = new Collector(trace, 500);
    _beeCollector.start();
}//GEN-LAST:event_beeRealTimeScoreActionPerformed

private void psoRealTimeScoreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_psoRealTimeScoreActionPerformed
    if(!_computation.isAlive())
        return;
    
    Chart2D chart = new Chart2D();
    ITrace2D trace = new Trace2DLtd(_realTimeBorder*2);
    trace.setColor(Color.RED);
    chart.addTrace(trace);

    _psoFrame = new JFrame("Pso Real Time Score");
    _psoFrame.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    _psoFrame.getContentPane().add(chart);
    _psoFrame.setSize(400, 300);
    _psoFrame.setVisible(true);
    _psoCollector = new Collector(trace, 500);
    _psoCollector.start();
}//GEN-LAST:event_psoRealTimeScoreActionPerformed

private void startActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startActionPerformed
    if (_computation.isAlive())
        return;
    
    start.setEnabled(false);
    _selectedCheckBox = 0;
    
    if(beeCheckBox.isSelected() && psoCheckBox.isSelected() && glowWormCheckBox.isSelected()){
        _computation = _computation = new Computation (_problem, _bees, _pso, _glowworm, this);
        _selectedCheckBox = 3;
        beeStatusLabel.setText("In progress ...");
        beeProgressBar.setValue(0);
        _iterations.put(GUI.BEES, 0);
        psoStatusLabel.setText("In progress ...");
        psoProgressBar.setValue(0);
        _iterations.put(GUI.PSO, 0);
        glowwormStatusLabel.setText("In progress ...");
        glowwormProgressBar.setValue(0);
        _iterations.put(GUI.GW, 0);
    }
    else if(beeCheckBox.isSelected() && psoCheckBox.isSelected() && !glowWormCheckBox.isSelected()){
        _computation = _computation = new Computation (_problem, _bees, _pso, null, this);
        _selectedCheckBox = 2;
        beeStatusLabel.setText("In progress ...");
        beeProgressBar.setValue(0);
        _iterations.put(GUI.BEES, 0);
        psoStatusLabel.setText("In progress ...");
        psoProgressBar.setValue(0);
        _iterations.put(GUI.PSO, 0);
    }
    else if(beeCheckBox.isSelected() && !psoCheckBox.isSelected() && glowWormCheckBox.isSelected()){
        _computation = _computation = new Computation (_problem, _bees, null, _glowworm, this);
        _selectedCheckBox = 2;
        beeStatusLabel.setText("In progress ...");
        beeProgressBar.setValue(0);
        _iterations.put(GUI.BEES, 0);
        glowwormStatusLabel.setText("In progress ...");
        glowwormProgressBar.setValue(0);
        _iterations.put(GUI.GW, 0);
    }
    else if(!beeCheckBox.isSelected() && psoCheckBox.isSelected() && glowWormCheckBox.isSelected()){
        _computation = _computation = new Computation (_problem, null, _pso, _glowworm, this);
        _selectedCheckBox = 2;
        psoStatusLabel.setText("In progress ...");
        psoProgressBar.setValue(0);
        _iterations.put(GUI.PSO, 0);
        glowwormStatusLabel.setText("In progress ...");
        glowwormProgressBar.setValue(0);
        _iterations.put(GUI.GW, 0);
    }
    else if(beeCheckBox.isSelected()){
        _computation = _computation = new Computation (_problem, _bees, null, null, this);
        _selectedCheckBox = 1;
        beeStatusLabel.setText("In progress ...");
        beeProgressBar.setValue(0);
        _iterations.put(GUI.BEES, 0);
    }
    else if(psoCheckBox.isSelected()){
        _computation = _computation = new Computation (_problem, null, _pso, null, this);
        _selectedCheckBox = 1;
        psoStatusLabel.setText("In progress ...");
        psoProgressBar.setValue(0);
        _iterations.put(GUI.PSO, 0);
    }
    else if(glowWormCheckBox.isSelected()){
        _computation = _computation = new Computation (_problem, null, null, _glowworm, this);
        _selectedCheckBox = 1;
        glowwormStatusLabel.setText("In progress ...");
        glowwormProgressBar.setValue(0);
        _iterations.put(GUI.GW, 0);
    }
    
    _computation.start();
    start.setEnabled(false);
}//GEN-LAST:event_startActionPerformed

    private void glowwormRealTimeScoreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_glowwormRealTimeScoreActionPerformed
    if(!_computation.isAlive())
        return;
    
    Chart2D chart = new Chart2D();
    ITrace2D trace = new Trace2DLtd(_realTimeBorder*2);
    trace.setColor(Color.RED);
    chart.addTrace(trace);

    _glowFrame = new JFrame("Glow Real Time Score");
    _glowFrame.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    _glowFrame.getContentPane().add(chart);
    _glowFrame.setSize(400, 300);
    _glowFrame.setVisible(true);
    _glowCollector = new Collector(trace, 500);
    _glowCollector.start();
    }//GEN-LAST:event_glowwormRealTimeScoreActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox beeCheckBox;
    private javax.swing.JLabel beeIteration;
    private javax.swing.JPanel beePanel;
    private javax.swing.JProgressBar beeProgressBar;
    private javax.swing.JButton beeRealTimeScore;
    private javax.swing.JLabel beeScore;
    private javax.swing.JLabel beeStatusLabel;
    private javax.swing.JCheckBox glowWormCheckBox;
    private javax.swing.JLabel glowwormIteration;
    private javax.swing.JProgressBar glowwormProgressBar;
    private javax.swing.JButton glowwormRealTimeScore;
    private javax.swing.JLabel glowwormScore;
    private javax.swing.JLabel glowwormStatusLabel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JCheckBox psoCheckBox;
    private javax.swing.JLabel psoIteration;
    private javax.swing.JPanel psoPanel;
    private javax.swing.JProgressBar psoProgressBar;
    private javax.swing.JButton psoRealTimeScore;
    private javax.swing.JLabel psoScore;
    private javax.swing.JLabel psoStatusLabel;
    private javax.swing.JButton start;
    // End of variables declaration//GEN-END:variables
}
